#include <iostream>
#include <cmath>
#define N 100

using namespace std;

void read_matrix(int matrix[N][N], int row, int column){
int i, j;
for (i=0;i<row;i++)
    for(j=0;j<column;j++){
        cout<<"["<<i<<"]["<<j<<"]= ";
        cin>>matrix[i][j];}
}

void print_matrix(int matrix[N][N], int row, int column){
int i,j;
for (i=0;i<row;i++){
    for(j=0; j<column; j++)
			cout<<matrix[i][j]<<" ";
		cout<<endl;}
}

int main(){
int row;
int column;
int matrix[N][N];
int i,j,k;
int sum=0;

cout<<"Type the number of rows: " ;
cin>>row;
cout<<"Type the number of columns: " ;
cin>>column;

read_matrix(matrix, row, column);
cout<<"A number to test divisibility: ";
cin>>k;
cout<<endl;

for(i=0;i<row;++i){
    for(j=0;j<column;++j)
        if(i==0 || j==0 || i== row-1 || j== column-1)
            if(matrix[i][j]%k==0)
                ++sum;
}

print_matrix(matrix, row,column);

cout<<"There are "<<sum<<" elements divisible with "<<k<<" , from the edge of the matrix."<<endl;

return 0;
}
